package com.oscar.ehome.view.pageview.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.oscar.ehome.R;
import com.oscar.ehome.bean.pagebean.DuDaoLieBiaoBean;
import com.oscar.ehome.bean.pagebean.InsuranceBean;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by juxing
 * author: MengWanhe
 * date: On 2017/12/21
 */

public class DuDaoAdapter extends BaseAdapter {

    private List<DuDaoLieBiaoBean.dudaoitem> list = new ArrayList<>();
    private LayoutInflater mInflater;
    private Context mContext = null;
    DuDaoLieBiaoBean.dudaoitem bean;


    public DuDaoAdapter(Context context, List<DuDaoLieBiaoBean.dudaoitem> list) {
        this.mContext = context;
        this.list = list;
        mInflater = LayoutInflater.from(context);
    }

    public void setLists(List<DuDaoLieBiaoBean.dudaoitem> list) {
        this.list = list;
        notifyDataSetChanged();
    }

    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int position) {
        return list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(final int position, View convertView, ViewGroup parent) {
        DuDaoAdapter.ViewHolder holder;
        if (convertView == null) {
            convertView = mInflater.inflate(R.layout.dudaolistitem, null);
            holder = new DuDaoAdapter.ViewHolder();
            holder.dudaoitenname = (TextView) convertView.findViewById(R.id.dudaoitenname);
            holder.dudaoitenmiaoshu = (TextView) convertView.findViewById(R.id.dudaoitenmiaoshu);

            convertView.setTag(holder); //
        } else {
            holder = (DuDaoAdapter.ViewHolder) convertView.getTag(); //
        }

        if (list.size() > 0) {
            if (list.get(position) != null) {
                bean = list.get(position);
                if (bean.getLabel() != null) {
                    holder.dudaoitenname.setText(bean.getLabel());
                } else {
                    holder.dudaoitenname.setText("活动");
                }
                if (bean.getRemarks() != null) {
                    holder.dudaoitenmiaoshu.setText(bean.getRemarks());
                } else {
                    holder.dudaoitenmiaoshu.setText("活动上报数据");
                }
//                if (bean.getMobile() != null) {
//                    holder.toubbao_phone_text.setText(bean.getMobile());
//                } else {
//                    holder.toubbao_phone_text.setText("暂无");
//                }
            }
        }
        return convertView;
    }

    class ViewHolder {
        TextView dudaoitenname;//投保人
        TextView dudaoitenmiaoshu;//投保人电话

    }
}
